rm(list=ls())

library(foreign)
library(ggplot2)
library(ggpubr)

setwd("")

canvass<-read.dta("GMA_canvass_effects.dta")
phone<-read.dta("GMA_phone_effects.dta")
mail<-read.dta("GMA_mail_effects.dta")

################# Relative to all, Dist

attach(phone) 
all3<-phone

plot1<- ggplot(all3, aes(phoneatt)) +
  geom_density(alpha = 0.5, fill = "#6a3d9a", colour = "#6a3d9a") + 
  geom_density(data = mail, aes(mailitt),  alpha = 0.5, fill = "#ff7f00", colour = "#ff7f00") + 
  geom_density(data = canvass, aes(canvassatt),  alpha = 0.5, fill = "#33a02c", colour = "#33a02c") + 
  theme_bw() +
  labs(x="Effect on Voter Turnout (Percentage Points)", y="Density", title="") +
  theme(text = element_text(size=24)) + 
  theme(legend.position="none") +
  geom_segment(aes(x = 3.2, y = 0.05, xend = 13.8, yend = 0.05), colour = "#1f78b4", size=3) +  
  annotate("point", x = 8.6, y = 0.05, colour = "#1f78b4", size=9,  alpha=1)  +
  annotate("text", x = 25, y = 0.05, label="TFA Effect", fontface="bold", colour = "#1f78b4", size=8) +
  annotate("text", x = 25, y = 0.23, label="Effect of Mailers", fontface="bold", colour = "#ff7f00", size=8) +
  annotate("text", x = 25, y = 0.22, label="Effect of Canvassing", fontface="bold", colour = "#33a02c", size=8) +
  annotate("text", x = 25, y = 0.21, label="Effect of Phone Calls", fontface="bold", colour = "#6a3d9a", size=8) 



plot1

ggsave(plot1, file="tfa_relative_all_gotv.pdf", width=8, height=5, scale=2)

################# Relative to all, Loli


loly<-read.csv("effectsizeloly.csv")

color.names<-c("#33a02c", "#ff7f00", "#6a3d9a", "#1f78b4")

plot2<-ggplot(loly, aes(y=effect, x=reorder(treatment, num)))  + 
  geom_point(size=24, aes(colour = factor(treatment))) +  theme_bw() +
  geom_segment(aes(x = num, y = 0, xend = num , yend = effect, colour = factor(treatment)), size=3) +
  scale_colour_manual(values=color.names) +
  theme(legend.position="none", legend.direction="horizontal") +  theme(legend.title=element_blank()) +
  theme(text = element_text(size=25)) +
  labs(x="Average Treatment Effect", y="Effect on Voter Turnout (Percentage Points)", title="") +
  annotate("text", x=1, y = 0.743, label = "0.7", size=10, fontface="bold", colour="white") +
  annotate("text", x=2, y = 0.627, label = "0.6", size=10, fontface="bold", colour="white") +
  annotate("text", x=3, y = 2.536, label = "2.5", size=10, fontface="bold", colour="white") +
  annotate("text", x=4, y = 8.6, label = "8.6", size=10, fontface="bold", colour="white") +
  geom_rect(aes(xmin=3.5, xmax=Inf, ymin=-Inf, ymax=Inf), alpha=0.07, fill="grey50") 

plot2
ggsave(plot2, file="effectcomparison.pdf", width=4, height=7, scale=2)

###### Bring Both Together
figure <- ggarrange(plot1, plot2,
                    labels = c("", "", ""),
                    ncol = 2, nrow = 1)
figure

ggsave(figure, file="bothcombined.pdf", width=8, height=5, scale=2)
